package cn.edu.uestc.software.controller;

import cn.edu.uestc.software.pojo.User;
import cn.edu.uestc.software.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;


    @RequestMapping("/selectUsers")
    public Map<String, Object> selectUsers(@RequestParam int page,
                                           String roleName,
                                           String roleLevel,
                                           String userName,
                                           String departmentName) {
        return userService.selectUsers(page,roleName,roleLevel,userName,departmentName);
    }

    @RequestMapping("/update")
    public Map<String,Object> Update(@RequestBody User user){
        return userService.Update(user);
    }

    @RequestMapping("/selectUserById")
    public Map<String,Object> selectUserById(@RequestParam String id){

        return userService.SelsctUserById(id);
    }

    @RequestMapping("/delete")
    public Map<String,Object> DeleteById(@RequestParam String id){

        return userService.DeleteById(id);
    }

    @RequestMapping("/insertUser")
    public Map<String,Object> InsertUser(@RequestParam String username,
                                         @RequestParam String password){

        return userService.InsertUser(username, password);
    }

//    @RequestMapping("/InsertUser02")
//
//    }

    @RequestMapping("/insert")
    public Map<String,Object> InsertUserJSON(@RequestBody User user){

        return userService.InsertUserJSON(user);
    }


    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Map<String, Object> login(@RequestBody User user, HttpServletRequest request) {
        return userService.login(user, request);
    }
}